package com.qiangqiang.task.server.mapper.provider;

import com.qiangqiang.task.server.entity.Comments;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2018-12-27 16:26
 **/
public class CommentsProvider extends BaseProvider {

    public String insertComments(final Map<String, Object> map) {
        Comments comments = (Comments) map.get("comments");
        return generateInsertSQL(Comments.class);
    }

    public String queryAllComments(final Map<String, Object> map) {
        final int page = (int) map.get("page");
        final int pageSize = (int) map.get("pageSize");
        final long postId = (long) map.get("postId");

        SQL sql = new SQL() {
            {
                SELECT("*");
                FROM("comments ");
                WHERE("post_id=" + postId);
                ORDER_BY("update_time ");
            }
        };
        StringBuffer sb = new StringBuffer(sql.toString());
        sb.append(getLimit(page, pageSize));
        return sb.toString();
    }
}

